<?php

namespace app\api\model;

use think\Model;
//加载admin模块语言包
\think\Lang::load(APP_PATH  . '/admin/lang/zh-cn/rush/order.php');

class RushOrder extends Model
{

    

    

    // 表名
    protected $name = 'rush_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'order_status_text',
        'complain_status_text'
    ];
    

    
    public function getOrderStatusList()
    {
        return ['0' => __('Order_status 0'), '1' => __('Order_status 1'), '2' => __('Order_status 2'), '3' => __('Order_status 3'), '4' => __('Order_status 4'), '11' => __('Order_status 11')];
    }

    public function getComplainStatusList()
    {
        return ['0' => __('Complain_status 0'), '1' => __('Complain_status 1')];
    }


    public function getOrderStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
        $list = $this->getOrderStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getComplainStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['complain_status']) ? $data['complain_status'] : '');
        $list = $this->getComplainStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function buyer()
    {
        return $this->belongsTo('\app\common\model\User', 'buyer_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function seller()
    {
        return $this->belongsTo('\app\common\model\User', 'seller_id', 'id', [], 'INNER')->setEagerlyType(0);
    }

    public function getGoodsImageAttr($value){
        return !empty($value) ? cdnurl($value) : '';
    }

    public function getPaymentVoucherAttr($value){
        if(!$value) return [];
        $images = explode(',',$value);
        foreach ($images as &$image){
            $image = cdnurl($image);
        }
        unset($image);
        return $images;
    }
}
